package merge;

/**
 * Created by hps on 17-5-1.
 */
public class MergeApp {
    public static void main(String[] args) {
        int[] arrA = {23, 47, 81, 95};
        int[] arrB = {7, 14, 39, 55, 62, 75};
        int[] arrC = new int[10];

        merge(arrA, arrB, arrC);

        for (int i = 0; i < 10; i++) {
            System.out.print(arrC[i] + " ");
        }
    }

    public static void merge(int[] a, int[] b, int[] c) {
        int sizeA = a.length, sizeB = b.length;
        int i = 0, j = 0;
        int k = 0;
        while (i < sizeA && j < sizeB) {
            if(a[i] < b[j])
                c[k++] = a[i++];
            else if(b[j] < a[i])
                c[k++] = b[j++];
        }

        if(i == sizeA) {
            while (j < sizeB)
                c[k++] = b[j++];
        }
        if(j == sizeB) {
            while (i < sizeA)
                c[k++] = a[i++];
        }
    }
}
